package com.yehangtech.designpattern.结构型_享元模式.utils;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class RedisUtil {
    private final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
    private final AtomicInteger stock = new AtomicInteger(0);

    public RedisUtil() {
        //每一秒库存+1
        scheduledExecutorService.scheduleAtFixedRate(() -> {
            stock.addAndGet(1);
        }, 0, 500, TimeUnit.MILLISECONDS);
    }

    public int getStockUsed() {
        return stock.get();
    }

}
